package com.example.basestationforballonproject;

import com.example.basestationforballonproject.utils.ExternalStorageFileWriter;
import com.example.basestationforballonproject.utils.SMSBroadcastReceiver;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.os.PowerManager;
import android.util.Log;


public class BaseStationService extends Service {

	private PowerManager.WakeLock wakelock;
	public static ExternalStorageFileWriter logger = new ExternalStorageFileWriter();


	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {

		Log.d(MainActivity.LOG_TAG, "Service onStartCommand");
		PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
		wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TurnOfScreenButStayWithMe");
		wakelock.acquire();

		BaseStationService.logger.fileLog("Service started, wakelock acquired");

		new SMSBroadcastReceiver();
		return super.onStartCommand(intent, flags, startId);
	}

	@Override
	public void onDestroy() {
		wakelock.release();
		Log.d(MainActivity.LOG_TAG, "Service onDestroy");
		logger.fileLog("Service destroyed, wakelock released");
		super.onDestroy();
	}

	@Override
	public IBinder onBind(Intent arg0) { return null; }
}
